# Copyright 2019 The IREE Authors
#
# Licensed under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

load("//build_tools/bazel:build_defs.oss.bzl", "iree_compiler_cc_library", "iree_gentbl_cc_library", "iree_tablegen_doc", "iree_td_library")
load("//build_tools/bazel:enforce_glob.bzl", "enforce_glob")

package(
    default_visibility = ["//visibility:public"],
    features = ["layering_check"],
    licenses = ["notice"],  # Apache 2.0
)

exports_files([
    "IREECodegenAttrs.td",
    "IREECodegenDialect.td",
    "IREECodegenInterfaces.td",
    "IREECodegenOps.td",
    "UKernelOps.td",
    "IREECodegenTypes.td",
])

iree_td_library(
    name = "td_files",
    srcs = enforce_glob(
        [
            "IREECodegenAttrs.td",
            "IREECodegenDialect.td",
            "IREECodegenInterfaces.td",
            "IREECodegenOps.td",
            "IREECodegenTypes.td",
            "UKernelOps.td",
        ],
        include = ["*.td"],
    ),
    deps = [
        "//compiler/src/iree/compiler/Codegen/Interfaces:td_files",
        "//compiler/src/iree/compiler/Utils:td_files",
        "@llvm-project//mlir:DestinationStyleOpInterfaceTdFiles",
        "@llvm-project//mlir:InferTypeOpInterfaceTdFiles",
        "@llvm-project//mlir:LinalgOpsTdFiles",
        "@llvm-project//mlir:OpBaseTdFiles",
        "@llvm-project//mlir:SCFTdFiles",
        "@llvm-project//mlir:SideEffectInterfacesTdFiles",
        "@llvm-project//mlir:TilingInterfaceTdFiles",
        "@llvm-project//mlir:VectorInterfacesTdFiles",
        "@llvm-project//mlir:ViewLikeInterfaceTdFiles",
    ],
)

iree_compiler_cc_library(
    name = "IREECodegenDialect",
    srcs = [
        "IREECodegenAttrs.cpp",
        "IREECodegenDialect.cpp",
        "IREECodegenInterfaces.cpp",
        "IREECodegenLibraryManager.cpp",
        "IREECodegenOps.cpp",
        "IREECodegenTypes.cpp",
        "TilingInterfaceImpl.cpp",
        "UKernelOps.cpp",
    ],
    hdrs = [
        "IREECodegenAttrs.h",
        "IREECodegenDialect.h",
        "IREECodegenEnums.h",
        "IREECodegenInterfaces.h",
        "IREECodegenOps.h",
        "IREECodegenTypes.h",
        "UKernelOps.h",
    ],
    textual_hdrs = [
        "IREECodegenAttrs.cpp.inc",
        "IREECodegenAttrs.h.inc",
        "IREECodegenDialect.cpp.inc",
        "IREECodegenDialect.h.inc",
        "IREECodegenEnums.cpp.inc",
        "IREECodegenEnums.h.inc",
        "IREECodegenInterfaces.cpp.inc",
        "IREECodegenInterfaces.h.inc",
        "IREECodegenOps.cpp.inc",
        "IREECodegenOps.h.inc",
        "IREECodegenTypes.h",
        "UKernelOps.cpp.inc",
        "UKernelOps.h.inc",
        "IREECodegenTypes.cpp.inc",
        "IREECodegenTypes.h.inc",
    ],
    deps = [
        ":IREECodegenDialectGen",
        ":IREECodegenOpsGen",
        ":IREECodegenTypesGen",
        ":LoweringConfigGen",
        ":LoweringConfigInterfaceGen",
        ":UKernelOpsGen",
        "//compiler/src/iree/compiler/Codegen/Interfaces:UKernelOpInterface",
        "//compiler/src/iree/compiler/Dialect/Util/IR",
        "@llvm-project//llvm:Support",
        "@llvm-project//mlir:AffineDialect",
        "@llvm-project//mlir:ArithDialect",
        "@llvm-project//mlir:ArithUtils",
        "@llvm-project//mlir:BufferizationDialect",
        "@llvm-project//mlir:DestinationStyleOpInterface",
        "@llvm-project//mlir:DialectUtils",
        "@llvm-project//mlir:FuncDialect",
        "@llvm-project//mlir:FunctionInterfaces",
        "@llvm-project//mlir:IR",
        "@llvm-project//mlir:InferTypeOpInterface",
        "@llvm-project//mlir:LinalgDialect",
        "@llvm-project//mlir:MemRefDialect",
        "@llvm-project//mlir:Parser",
        "@llvm-project//mlir:SCFDialect",
        "@llvm-project//mlir:SCFTransforms",
        "@llvm-project//mlir:Support",
        "@llvm-project//mlir:TensorDialect",
        "@llvm-project//mlir:TilingInterface",
        "@llvm-project//mlir:TransformDialect",
        "@llvm-project//mlir:TransformDialectTransforms",
        "@llvm-project//mlir:VectorInterfaces",
        "@llvm-project//mlir:ViewLikeInterface",
    ],
)

iree_gentbl_cc_library(
    name = "IREECodegenDialectGen",
    tbl_outs = [
        (
            ["--gen-dialect-decls"],
            "IREECodegenDialect.h.inc",
        ),
        (
            ["--gen-dialect-defs"],
            "IREECodegenDialect.cpp.inc",
        ),
    ],
    tblgen = "@llvm-project//mlir:mlir-tblgen",
    td_file = "IREECodegenDialect.td",
    deps = [":td_files"],
)

iree_gentbl_cc_library(
    name = "IREECodegenOpsGen",
    tbl_outs = [
        (
            ["--gen-op-decls"],
            "IREECodegenOps.h.inc",
        ),
        (
            ["--gen-op-defs"],
            "IREECodegenOps.cpp.inc",
        ),
    ],
    tblgen = "@llvm-project//mlir:mlir-tblgen",
    td_file = "IREECodegenOps.td",
    deps = [
        ":td_files",
        "//compiler/src/iree/compiler/Codegen/Interfaces:td_files",
    ],
)

iree_gentbl_cc_library(
    name = "LoweringConfigInterfaceGen",
    tbl_outs = [
        (
            ["--gen-attr-interface-decls"],
            "IREECodegenInterfaces.h.inc",
        ),
        (
            ["--gen-attr-interface-defs"],
            "IREECodegenInterfaces.cpp.inc",
        ),
    ],
    tblgen = "@llvm-project//mlir:mlir-tblgen",
    td_file = "IREECodegenInterfaces.td",
    deps = [":td_files"],
)

iree_gentbl_cc_library(
    name = "LoweringConfigGen",
    tbl_outs = [
        (
            ["--gen-attrdef-decls"],
            "IREECodegenAttrs.h.inc",
        ),
        (
            ["--gen-attrdef-defs"],
            "IREECodegenAttrs.cpp.inc",
        ),
        (
            ["--gen-enum-decls"],
            "IREECodegenEnums.h.inc",
        ),
        (
            ["--gen-enum-defs"],
            "IREECodegenEnums.cpp.inc",
        ),
    ],
    tblgen = "@llvm-project//mlir:mlir-tblgen",
    td_file = "IREECodegenAttrs.td",
    deps = [":td_files"],
)

iree_gentbl_cc_library(
    name = "IREECodegenTypesGen",
    tbl_outs = [
        (
            ["--gen-typedef-decls"],
            "IREECodegenTypes.h.inc",
        ),
        (
            ["--gen-typedef-defs"],
            "IREECodegenTypes.cpp.inc",
        ),
    ],
    tblgen = "@llvm-project//mlir:mlir-tblgen",
    td_file = "IREECodegenTypes.td",
    deps = [
        ":td_files",
        "//compiler/src/iree/compiler/Codegen/Interfaces:td_files",
    ],
)

iree_gentbl_cc_library(
    name = "UKernelOpsGen",
    tbl_outs = [
        (
            ["--gen-op-decls"],
            "UKernelOps.h.inc",
        ),
        (
            ["--gen-op-defs"],
            "UKernelOps.cpp.inc",
        ),
    ],
    tblgen = "@llvm-project//mlir:mlir-tblgen",
    td_file = "UKernelOps.td",
    deps = [
        ":td_files",
        "//compiler/src/iree/compiler/Codegen/Interfaces:td_files",
    ],
)

iree_tablegen_doc(
    name = "IREECodegenDialectDocGen",
    category = "Dialects",
    tbl_outs = [
        (
            [
                "--gen-dialect-doc",
                "--dialect=iree_codegen",
            ],
            "IREECodegenDialect.md",
        ),
    ],
    tblgen = "@llvm-project//mlir:mlir-tblgen",
    td_file = "IREECodegenOps.td",
    deps = [":td_files"],
)
